package com.wheat.vipcard.bean;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * Tabdiscount entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.wheat.vipcard.bean.Tabdiscount
 * @author MyEclipse Persistence Tools
 */

public class TabdiscountDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(TabdiscountDAO.class);
	// property constants
	public static final String DIS_ID = "disId";
	public static final String DIS_TITLE = "disTitle";
	public static final String DIS_CONSUME = "disConsume";
	public static final String DIS_IMAGE = "disImage";
	public static final String DIS_IMAGE_CONTENT = "disImageContent";
	public static final String DIS_SPECIAL_TIPS = "disSpecialTips";
	public static final String DIS_PRICE = "disPrice";
	public static final String DIS_TIME = "disTime";
	public static final String DIS_COUNT = "disCount";
	public static final String DIS_ADDRESS = "disAddress";

	public void save(Tabdiscount transientInstance) {
		log.debug("saving Tabdiscount instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Tabdiscount persistentInstance) {
		log.debug("deleting Tabdiscount instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Tabdiscount findById(java.lang.Integer id) {
		log.debug("getting Tabdiscount instance with id: " + id);
		try {
			Tabdiscount instance = (Tabdiscount) getSession().get(
					"com.wheat.vipcard.bean.Tabdiscount", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Tabdiscount instance) {
		log.debug("finding Tabdiscount instance by example");
		try {
			List results = getSession().createCriteria(
					"com.wheat.vipcard.bean.Tabdiscount").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Tabdiscount instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Tabdiscount as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByDisId(Object disId) {
		return findByProperty(DIS_ID, disId);
	}

	public List findByDisTitle(Object disTitle) {
		return findByProperty(DIS_TITLE, disTitle);
	}

	public List findByDisConsume(Object disConsume) {
		return findByProperty(DIS_CONSUME, disConsume);
	}

	public List findByDisImage(Object disImage) {
		return findByProperty(DIS_IMAGE, disImage);
	}

	public List findByDisImageContent(Object disImageContent) {
		return findByProperty(DIS_IMAGE_CONTENT, disImageContent);
	}

	public List findByDisSpecialTips(Object disSpecialTips) {
		return findByProperty(DIS_SPECIAL_TIPS, disSpecialTips);
	}

	public List findByDisPrice(Object disPrice) {
		return findByProperty(DIS_PRICE, disPrice);
	}

	public List findByDisTime(Object disTime) {
		return findByProperty(DIS_TIME, disTime);
	}

	public List findByDisCount(Object disCount) {
		return findByProperty(DIS_COUNT, disCount);
	}

	public List findByDisAddress(Object disAddress) {
		return findByProperty(DIS_ADDRESS, disAddress);
	}

	public List findAll() {
		log.debug("finding all Tabdiscount instances");
		try {
			String queryString = "from Tabdiscount";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Tabdiscount merge(Tabdiscount detachedInstance) {
		log.debug("merging Tabdiscount instance");
		try {
			Tabdiscount result = (Tabdiscount) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Tabdiscount instance) {
		log.debug("attaching dirty Tabdiscount instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Tabdiscount instance) {
		log.debug("attaching clean Tabdiscount instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}